package lambda;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class TestLambda02 {

    List<Person> dataList = Arrays.asList(
            new Person(30, "周瑞"),
            new Person(32, "小关"),
            new Person(6, "周灏宇"),
            new Person(1, "周灏昂"),
            new Person(10, "张三"),
            new Person(10, "王五"),
            new Person(15, "李四"));

    /**
     * 对上面list，先按年龄排序，年龄相等的情况下，按名字排序
     */
    @Test
    public void test01() {
        Collections.sort(dataList, (e1, e2) -> {
            if (e1.getAge() == e2.getAge()) {
                return e1.getName().compareTo(e2.getName());
            } else {
                return Integer.compare(e1.getAge(), e2.getAge());
            }
        });
        for (Person person: dataList) {
            System.out.println(person);
        }
    }
}
